const mongoose = require('./db')

const userSchema = new mongoose.Schema({
    uname: String,
    email: String,
    pwd: String,
    phone: String,
    sex: Number,
    birthday: String,
    imgsrc: String,
    roleid: {
        ref: 'role',
        type: mongoose.Types.ObjectId
    },
    istop: {
        type: Boolean,
        default: false
    },
    // 是否已读
    isread: {
        type: Boolean,
        default: false
    }
})


const roleSchema = new mongoose.Schema({
    rname: String
})

const roleModel = mongoose.model("role", roleSchema, "role")

const listSchema = new mongoose.Schema({

})

const messageSchema = new mongoose.Schema({
    from: String,
    to: String,
    message: String,
    voice: String,
    time: String
})

// 门店信息
const salonSchema = new mongoose.Schema({
    name: String,
    address: String,
    phone: String,
    openingHours: [String],
    description: String,
    location: {
        type: { type: String, default: "Point" },
        coordinates: [String]
    },
    images: [String],//相册照片
    staus: { type: Number, default: 1 },//状态 1正常 0下架
    type: Array,//门店类型
    gl: String,//距离多远
    pj: String,//评分
})
// 服务信息
const serviceSchema = new mongoose.Schema({
    name: String,
    salonId: { type: mongoose.Schema.Types.ObjectId, ref: "salon" },
    price: Number,
    description: String,//服务描述
    tid: { type: mongoose.Schema.Types.ObjectId, ref: "service" },
    photoUrl: String//照片链接
})
// 理发师信息
const stylistSchema = new mongoose.Schema({
    name: String,
    salonId: { type: mongoose.Schema.Types.ObjectId, ref: "salon" },
    bio: String,//个人简介
    specialties: [String],//特长列表
    photoUrl: String,//照片链接
    sex: String,//性别
    age: Number,//年龄
    phone: {
        type: String,
        default: "19266668888"
    },//电话
    uname: String,//用户名
    pwd: String,//密码
})
// 套餐信息表
const packageSchema = new mongoose.Schema({
    img: String,// 套餐图片
    name: String,//套餐名称
    salonId: { type: mongoose.Schema.Types.ObjectId, ref: "salon" },//所属门店
    price: Number,//价格
    description: String,//描述
    services: [{ type: mongoose.Schema.Types.ObjectId, ref: "service" }]//服务列表
})
// 评价信息表
const reviewSchema = new mongoose.Schema({
    userId: { type: mongoose.Schema.Types.ObjectId, ref: "user" },//用户id
    stylistId: { type: mongoose.Schema.Types.ObjectId, ref: "stylist" },//理发师id
    salonId: { type: mongoose.Schema.Types.ObjectId, ref: "salon" },//门店id
    serviceId: { type: mongoose.Schema.Types.ObjectId, ref: "service" },//服务id
    packageId: { type: mongoose.Schema.Types.ObjectId, ref: "package" },//套餐id
    orderId: { type: mongoose.Schema.Types.ObjectId, ref: "order" },//订单id
    content: String,//评价内容
    rating: Number,//评分
    image: String,//评价图片
    createTime: { type: Date, default: Date.now },//评价时间
    rid: { type: mongoose.Schema.Types.ObjectId, ref: "review" },//回复id
    flag: Boolean,//是否匿名 0否 1是
})

// 支付成功后订单信息表
const orderSchema = new mongoose.Schema({
    amout: Number,//订单金额
    trade: String,//交易号
    stylistId: { type: mongoose.Schema.Types.ObjectId, ref: "stylist" },//理发师id
    salonId: { type: mongoose.Schema.Types.ObjectId, ref: "salon" },//门店id
    serviceId: { type: mongoose.Schema.Types.ObjectId, ref: "service" },//服务id
    packageId: { type: mongoose.Schema.Types.ObjectId, ref: "package" },//套餐id
    time: String,//预约时间
    phone: String,//手机号
    username: String,//用户名
    //怎么定义使用完成后状态
    status: { type: Number, default: 0 },//状态 0未使用 1已使用 2已取消,
    remind: { type: Boolean, default: false },//状态 等待商家确认
    creatTime: { type: Date, default: Date.now },//创建时间
    ispj: { type: Boolean, default: false },//是否评价 0未评价 1已评价
})
// 姜思兵的理发店表
const BarberSchema = new mongoose.Schema({
    name: String,
    price: Number,
    type: Array,
    postton: String,
    jwd: Object,
    time: String,
    gl: Number,
    pj: Number,
    pls: Number,
})
//通知表
const tzSchema = new mongoose.Schema({
    title:String,
    content:String,
    time:Date,
    pid:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"user"
    }
})
const list = mongoose.model("list", listSchema, "list")
const messageModel = mongoose.model("message", messageSchema, "message")
const tzModel = mongoose.model("tz", tzSchema, "tz") //通知
const BarberModel = mongoose.model("barber", BarberSchema, "barber")
const userModel = mongoose.model("user", userSchema, 'user')//用户
const salonModel = mongoose.model("salon", salonSchema, 'salon')//门店
const serviceModel = mongoose.model("service", serviceSchema, 'service')//服务
const stylistModel = mongoose.model("stylist", stylistSchema, 'stylist')//理发师
const orderModel = mongoose.model('order', orderSchema, 'order')//订单
const packageModel = mongoose.model('package', packageSchema, 'package')//套餐
const reviewModel = mongoose.model('review', reviewSchema, 'review')//评价

module.exports = {
    userModel,
    salonModel,
    serviceModel,
    stylistModel,
    orderModel,
    packageModel,
    reviewModel,
    list,
    messageModel,
    userModel,
    roleModel,
    BarberModel,
    tzModel
}